package arrayList;

import common.Person;
import utils.Asserts;

/**
 * Author: 陈艺博
 * Date:  2021-01-16 20:05
 * Description:
 */
public class ArrayListTest {
    public static void main(String[] args) {
        // 测试一: 测试添加操作
/*        ArrayList<Object> list = new ArrayList<>();
        list.add(10);
        list.add(20);
        list.add(new Person(10,"Jack"));
        System.out.println(list.size());
        list.add(3,50);
        System.out.println(list.size());
        System.out.println(list.get(1));
        System.out.println(list);*/

        // 测试而: 测试查找操作
/*        ArrayList<Object> persons  = new ArrayList<>();
        persons.add(new Person(10, "Jack"));
        persons.add(null);
        persons.add(new Person(15, "Rose"));
        persons.add(null);
        persons.add(new Person(12, "James"));
        persons.add(null);

        System.out.println(persons.indexOf(null));
        System.out.println(persons.size());*/

        // 测试三 测试清空操作
        ArrayList<Person> persons = new ArrayList<>();
        persons.add(new Person(10, "Jack"));
        persons.add(new Person(12, "James"));
        persons.add(new Person(15, "Rose"));
        // 将数组元素中所指向null
        persons.clear();
        // 调用GC, 验证对象回收机制
        System.gc();

        //todo 使用测试工具类
        Asserts.test(persons.size()==1);
        persons.add(new Person(22, "abc"));
        System.out.println(persons);

        ArrayList<Integer> ints = new ArrayList<>();
        ints.add(10);
        ints.add(10);
        ints.add(22);
        ints.add(33);
        System.out.println(ints);
    }
}
